package com.atguigu.controller;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @description:
 * @author: KeepFresh
 * @time: 2021/4/15 19:56
 */
public class ThreeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 1、分别将共享数据添加到作用域对象
        ServletContext application = req.getServletContext();
        HttpSession session = req.getSession();

        application.setAttribute("sid", 10);
        session.setAttribute("sname", "mike");
        req.setAttribute("home", "浦东新区");

        // 2、通过请求转发的方式，向tomcat申请调用one.jsp，由one.jsp负责将
        // 作用域对象共享数据读取并写入到响应体中，交给浏览器
        req.getRequestDispatcher("/one.jsp").forward(req,resp);
    }

}
